# coding=utf-8

import getpass
import os

userName = getpass.getuser()
basePath = '/Users/' + userName + '/Desktop/testfile/'

# 获取当前create编号
def getIndex():
    mkdir(basePath)
    filePath = basePath+'index'
    fileCreate(filePath)
    inputStr = fileRade(filePath)
    if (inputStr == ''):
        inputStr = '0'
    inputNum = int(inputStr)
    inputNum = inputNum + 1
    fileWrite(filePath, str(inputNum))
    return inputNum


def fileRade(filePath):
    file_read = open(filePath)
    try:
        all_the_text = file_read.read()
        return all_the_text
    finally:
        file_read.close()


def fileWrite(filePth, outputStr):
    file_write = open(filePth, 'w')
    try:
        file_write.write(outputStr)
    finally:
        file_write.close()

def fileCreate(name):
    file = open(name,'a')
    file.close()



def mkdir(path):
    path = path.strip()
    path = path.rstrip("\\")
    isExists = os.path.exists(path)
    if not isExists:
        os.makedirs(path)
        return True


